<template>
  <div>
    <!-- 面包线导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- ka片视图 -->

    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <!-- 将搜索框绑定参数的query属性上 -->
          <el-input>
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 表格 -->
      <el-table :data="ordersList" style="width: 100%" border>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number" width="200px"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否支付">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.order_pay ==='1'">已支付</el-tag>
            <el-tag type="danger" v-else>未支付</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="创建时间" prop="create_time">
          <template slot-scope="scope">{{scope.row.create_time | dateFormat}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="adressDialogVisible=true"
            ></el-button>
            <el-button type="success" icon="el-icon-setting" size="mini" @click="progressDialog()"></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 地址更改的对话框 -->
    <el-dialog title="更改地址" :visible.sync="adressDialogVisible" width="50%" @close="addressClose">
      <!-- 级联选择器 -->
      <el-form
        :rules="addressFormRules"
        label-position="right"
        :model="addressForm"
        ref="addressForm"
      >
        <el-form-item label="省/市/区" prop="address1">
          <el-cascader :options="cityData" v-model="addressForm.address1" clearable></el-cascader>
        </el-form-item>
        <el-form-item label="具体地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="adressDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="adressDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 物流进度对话框 -->
    <el-dialog title="物流进度" :visible.sync="progressDialogVisible" width="50%">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in progressList"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="progressDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="progressDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
// 导入地址包
import cityData from './citydata.js'
export default {
  data() {
    return {
      // 请求列表参数
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      //   订单列表
      ordersList: [],
      // 数据条数
      total: 0,

      //   更改地址对话框显示隐藏
      adressDialogVisible: false,
      // 地址信息
      cityData,
      //   修改地址表单
      addressForm: {
        address1: [],
        address2: ''
      },
      //   修改表单验证规则
      addressFormRules: {
        address2: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ],
        address1: {
          required: true,
          message: '请选择活动区域',
          trigger: 'blur'
        }
      },
      //   物流进度对话框 显示隐藏
      progressDialogVisible: false,
      //   物流列表
      progressList: []
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    //   物流信息对话框打开
    async progressDialog() {
      // 获取信息
      var { data: res } = await this.$http.get('/kuaidi/804909574412544580')

      if (res.meta.status !== 200) {
        return this.$message.error('获取进度失败')
      }
      console.log(res.data)
      // 将数据放入表中
      this.progressList = res.data
      //   打开物流对话框
      this.progressDialogVisible = true
    },
    //   修改地址关闭
    addressClose() {
      this.$refs.addressForm.resetFields()
    },
    //  获取订单列表
    async getOrderList() {
      // 发请求
      var { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      // 判断
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败')
      }
      // 成功
      console.log(res.data)
      this.ordersList = res.data.goods
      this.total = res.data.total
    }
  }
}
</script>
<style lang="less" scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';

.el-cascader {
  width: 80%;
}
.el-input {
  width: 80%;
}
</style>
